/**
    Copyright (c) 2010-2011 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include <vector>

/**    
    @brief  Constant buffer struct for compute shader.
    @date   2010/01/30
*/
struct ConstantBuf
{
    // bounds of the complex number plane
    float    fMinRe;
    float    fMaxRe;
    float    fMinIm;
    float    fMaxIm;
    
    // step size for the complex number plane
    float    fStepRe;
    float    fStepIm;

    // width*height of the data buffer
    int        nSize;

    // width of the data buffer
    int        nWidth;

    // maximum iterations to decide whether an complex number is in the mandelbrot set.
    int        nMaxIterations;

    char  padding[ 12 ];        // constant buffer ByteWidth has to be multiple of 16
};

/**    
    @brief  Mandelbrot base class.
    @author yakiimo02
    @date   2010/01/30
*/
class MandelbrotBase
{
public:
    MandelbrotBase();
    virtual ~MandelbrotBase() = 0;

    virtual void OnFrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext,
                                  double fTime, float fElapsedTime, void* pUserContext ) = 0;

    void TranslateCenter( const D3DXVECTOR2& vDeltaCenter );
    void ZoomScale( const float fDeltaScale );

    inline void SetnMaxIterations( int nMaxIterations ) { m_nMaxIterations = nMaxIterations; }

    inline const ConstantBuf*     GetpConstantBuf() const { return &m_cb; }
    inline D3DXVECTOR2            GetvCenter() const { return m_vCenter; }
    inline float                  GetfZoomScale() const { return m_fZoomScale; }
    inline int                    GetnMaxIterations() const { return m_nMaxIterations; }

protected:
    void CreateColorTable();
    void UpdateConstantBuf( int nWidth, int nHeight );

protected:
    D3DXVECTOR2                     m_vCenter;
    float                           m_fZoomScale;
    unsigned int                    m_nMaxIterations;
    ConstantBuf                     m_cb;
};
